<?php
	
	include('cms.php');
	
	Cms::nocache();
	
	
	
	if(isset($_POST['newuser'])){
		//INSERT user
		$newuser = $_POST['newuser'];
		$user = new User();
		$user->mail = $newuser;
		$user->nick = $strings['newUserBracket'];
		$user->level = 0;
		$user->insert();
		
		echo OK;
		
	}elseif(isset($_POST['deleteuser'])){
		//DELETE user
		$iduser = DataLatte::escape($_POST['deleteuser']);
		
		DataLatte::update("DELETE FROM cmsUser WHERE iduser = '$iduser'");
		
		echo OK;
		
	}elseif(isset($_POST['newpass'])){
		//CHANGE password
		$iduser = DataLatte::escape($_POST['iduser']);
		$pass = DataLatte::escape($_POST['newpass']);
		
		DataLatte::update("UPDATE cmsUser SET pass = MD5('$pass') WHERE iduser = '$iduser'");
		
		echo OK;
		
	}else{
		//UPDATE user
		$iduser = DataLatte::escape($_POST['iduser']);
		
		$user = DataLatte::oneof('User', "SELECT * FROM cmsUser WHERE iduser = '$iduser'");
		
		if($user){
			
			$user->mail = $_POST['mail'];
			$user->nick = $_POST['nick'];
			$user->level = $_POST['level'];
			$user->admin = $_POST['admin'];
			$user->signature = $_POST['signature'];
			$user->update();
			
			echo OK;
			
		}else{
			$strings['invalidUser'];
		}
		
		
	}
	
	
?>